/**
 * 控制和生成导航条元素
 */
(function() {
    "use strict"

    var that;
    function MainNav(navdom) {
        // 添加 logo
        var logo = document.createElement("a");
        logo.style.cssText += ";color:#4169E1;line-height:3rem;height:100%;width:15%;text-align:center;float:left;font-weight:bold;";
        logo.href = "/";
        logo.innerText = "废人五号";
        navdom.appendChild(logo);
        // 按钮栏
        var btnBox = document.createElement("div");
        btnBox.style.cssText += ";width:75%;height:100%;float:left;";
        navdom.appendChild(btnBox);
        // 应用栏
        var appBox = document.createElement("div");
        appBox.style.cssText += ";float:right;width:10%;height:100%;";
        appBox.style.minWidth = "3rem";
        var appBtn = document.createElement("div");
        appBtn.style.cssText += ";position:relative;left:50%;width:2rem;height:2rem;margin-left:-1rem;margin-top:.5rem;background:red;";
        appBtn.style.cssText += ";display:inline-block;border-radius:2px;border:0;cursor:pointer;"
        appBtn.style.background = "url(/public/image-base/nav/app-base.png) no-repeat";
        appBtn.style.backgroundSize = "2rem";
        appBox.appendChild(appBtn);
        navdom.appendChild(appBox);

        navdom.style.cssText += ";width:80%;height:3rem;margin-left:10%;float:left";
        this.navdom = navdom;
        this.btnBox = btnBox;
        that = this;

        appBox.addEventListener("click", function(event) {
            Muggle.gets("#header-cover").style.display = "block";
        });
    }

    // 环境量缓存
    MainNav.prototype.Environment = {
        BtnCount: 0  // 按钮数量
    };

    // 普通按钮
    MainNav.prototype.AddBtn = function(data) {
        // 总数量等于现数量加原注册数量
        MainNav.prototype.Environment.BtnCount += data.length;
        var nomalBtn = [];
        for (var num in data) {
            var nomalBtn = document.createElement("a");
            var width = 100/(MainNav.prototype.Environment.BtnCount);
            nomalBtn.style.cssText += ";color:#888;line-height:3rem;height:100%;width:"+width+"%;text-align:center;float:left;";
            nomalBtn.href = data[num].link;
            nomalBtn.innerText = data[num].text;
            nomalBtn.target = "_blank";
            nomalBtn.addEventListener("mouseover", function(event) {
                this.style.color = "black";
                this.style.fontWeight = "bold";
            });
            nomalBtn.addEventListener("mouseout", function(event) {
                this.style.color = "#888";
                this.style.fontWeight = "normal";
            });
            that.btnBox.appendChild(nomalBtn);
        }
    };

    // LOGO 标志
    MainNav.prototype.LogoSet = function(data) {
        var logo = document.createElement("a");
    };

    window.MainNav = MainNav;
})();